package jianzhi_offer;

import java.util.LinkedList;
import java.util.Queue;

public class _32_丑数 {
    public int GetUglyNumber_Solution(int index) {
        //还可以把队列的值 放到数组里 这样队列里就避免有重复的值了
        if(index == 0) return 0;
        if(index == 1) return 1;
        int count = 1;
        Queue<Integer> two = new LinkedList<>();
        two.offer(2);
        Queue<Integer> three = new LinkedList<>();
        three.offer(3);
        Queue<Integer> five = new LinkedList<>();
        five.offer(5);

        int now = 1;
        for(int i=2;i<=index;++i){
            int min = Math.min(Math.min(two.peek(),three.peek()),five.peek());
            if(min == two.peek()) two.poll();
            if(min == three.peek()) three.poll();
            if(min == five.peek()) five.poll();
            two.offer(min*2);
            three.offer(min*3);
            five.offer(min*5);
            now = min;
        }
        return now;
    }
}
